const App = getApp()
Page({
  data: {
    showdialog: true,
    id: '',
    type: 'a',
    hidden: false,
    showpay: true
  },
  onLoad: function (options) {
    let that = this
    that.setData({
      type: options.type,
      id: options.id
    })
  },
  async orderdetail() {
    let that = this
    if (that.data.type == 'user') {
      await App.api.$http({
        url: 'Oilorder/detail',
        method: 'GET',
        data: {
          order_id: that.data.id
        }
      }, {}).then(res => {
        if (res) {
          that.setData({
            detail: res.data.order
          })
        }
      })
    } else {
      await App.api.$http({
        url: 'Oilorder/staffDetail',
        method: 'GET',
        data: {
          order_id: that.data.id
        }
      }, {}).then(res => {
        if (res) {
          that.setData({
            detail: res.data.order
          })
        }
      })
    }

  },
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that=this
    that.orderdetail()
  },
  photo() {
    wx.navigateTo({
      url: '/pages/car/photo/photo?id=' + this.data.id,
    })
  },

  inputtext(e) {
    let that = this
    console.log(e)
    var money;
    if (/^(\d?)+(\.\d{0,2})?$/.test(e.detail.value)) {
      money = e.detail.value;
    } else {
      money = e.detail.value.substring(0, e.detail.value.length - 1);
    }
    this.setData({
      oil: money,
    })
  },

  addoil() {
    let that = this
    that.setData({
      oil: '',
      showdialog: !that.data.showdialog
    })
  },
  confirm() {
    let that = this
    App.api.$http({
      url: 'Oilorder/staffCheck',
      method: 'GET',
      data: {
        oil_num: that.data.oil,
        order_id: that.data.id
      }
    }, {}).then(res => {
      that.setData({
        showdialog: true
      })
      if (res) {
        App.api.$showSuccess(res.msg)
        setTimeout(() => {
          that.orderdetail()
        }, 2000);
      }
    })
  },
  showpay(){
    let that = this
    that.setData({
      showpay: !that.data.showpay,
    })
  },
  cancel() {
    let that = this
    wx.showModal({
      title: '提示',
      content: '确认取消订单吗？',
      success(res) {
        if (res.confirm) {
          App.api.$http({
            url: 'Oilorder/staffCancel',
            method: 'GET',
            data: {
              order_id:that.data.id
            }
          }, {}).then(res => {
            if (res) {
              App.api.$showSuccess(res.msg)
              setTimeout(() => {
                wx.navigateBack()
              }, 2000);
            }
          })
        } else if (res.cancel) {}
      }
    })
  },
  tolocation() {
    let that = this
    const latitude = Number(that.data.detail.latitude)
    const longitude = Number(that.data.detail.longitude)
    wx.openLocation({
      latitude,
      longitude,
      scale: 15
    })
  },
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})